﻿/***************************
* 1.住列表
* 2.酒店列表
* 3.酒店详情
* 4.酒店预订
****************************/

/* 变量 */
var stay = "booking/stay.html";
var hotel = "booking/hotel.html";
var hotelDetail = "booking/hotelDetail.html";
var hotelBooking = "booking/hotelBooking.html";
var hotelPay = "booking/hotelPay.html";

/***********    地图使用公共方法    **********/
//地图跳转-类似周边，跳转景区，要iframe能使用
function MapClickJump(url, param) {
    mainView.router.loadPage({ url: url, reload: false });
}
//调用语音接口，返回给子界面--地图使用
var voice = {
    localId: '',
    serverId: ''
};
function ReturnStartVoice() {
    wx.startRecord({
        cancel: function () {
            alert('用户拒绝授权录音');
        }
    });
};
function ReturnEndVoid(callback) {
    wx.stopRecord({
        success: function (res) {
            voice.localId = res.localId;
            wx.translateVoice({
                localId: voice.localId, // 需要识别的音频的本地Id，由录音相关接口获得
                isShowProgressTips: 1, // 默认为1，显示进度提示
                success: function (res) {
                    if (res.translateResult != 'undefined' && res.translateResult != '') {
                        yy = res.translateResult.replace(/['",.!?，。？！]/ig, ""); // 语音识别的结果
                        callback(yy);
                    }
                }
            });
        },
        fail: function (res) {
            alert(JSON.stringify(res));
        }
    });
};
//语音按钮事件
/* 初始化语音config */
var gn = ['startRecord', 'stopRecord', 'translateVoice', 'openLocation', 'getLocation'];
wx_config(gn, function () {
    //callback 所有JSSDK事件
}, function () {
    //errorcallback  config注册失败事件
});
/***********    地图使用公共方法----结束    **********/

/* 住 */
var contactsCallback_stay = myApp.onPageInit('stay', function (page) {

    // 过滤 全部美食显示
    $$(".navbar-inner .right a img").hide();



    /* 筛选条件 */
    $$("#category_list ul li").hide();
    $$("#sel_hotel_price_range").show();
    $$("#sel_hotel_star").show();
    $$("#sel_hotel_type").show();



    var pickerRegion; //所在区域
    var pickerHotelStar; //酒店星级
    var pickerHotelType; //酒店类型
    var pickerHotelPriceRange; //价格范围
    var calendarIn; //入住时间
    var calendarOut; //离店时间

    pickerRegion = myApp.picker({
        input: '#sel_region_value',
        toolbarTemplate:
        '<div class="toolbar theme-red">' +
        '<div class="toolbar-inner">' +
        '<div class="left"></div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        formatValue: function (p, values, displayValues) {
            return displayValues;
        },
        cols: [
            {
                textAlign: 'center',
                values: (function () {
                    var arrValue = [];
                    $$.each(iss_dictionaryBaseData.district(), function (i, obj) {
                        arrValue.push(obj.value);
                    });
                    return arrValue;
                })(),
                displayValues: (function () {
                    var arrDisplay = [];
                    $$.each(iss_dictionaryBaseData.district(), function (i, obj) {
                        arrDisplay.push(obj.display);
                    });
                    return arrDisplay;
                })()
            }
        ]
    });

    pickerHotelStar = myApp.picker({
        input: '#sel_hotel_star_value',
        toolbarTemplate:
        '<div class="toolbar theme-red">' +
        '<div class="toolbar-inner">' +
        '<div class="left"></div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        formatValue: function (p, values, displayValues) {
            return displayValues;
        },
        cols: [
            {
                textAlign: 'center',
                values: (function () {
                    var arrValue = [];
                    $$.each(iss_dictionaryBaseData.hotelStar(), function (i, obj) {
                        arrValue.push(obj.value);
                    });
                    return arrValue;
                })(),
                displayValues: (function () {
                    var arrDisplay = [];
                    $$.each(iss_dictionaryBaseData.hotelStar(), function (i, obj) {
                        arrDisplay.push(obj.display);
                    });
                    return arrDisplay;
                })()
            }
        ]
    });

    pickerHotelType = myApp.picker({
        input: '#sel_hotel_type_value',
        toolbarTemplate:
        '<div class="toolbar theme-red">' +
        '<div class="toolbar-inner">' +
        '<div class="left"></div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        formatValue: function (p, values, displayValues) {
            return displayValues;
        },
        cols: [
            {
                textAlign: 'center',
                values: (function () {
                    var arrValue = [];
                    $$.each(iss_dictionaryBaseData.hotelType(), function (i, obj) {
                        arrValue.push(obj.value);
                    });
                    return arrValue;
                })(),
                displayValues: (function () {
                    var arrDisplay = [];
                    $$.each(iss_dictionaryBaseData.hotelType(), function (i, obj) {
                        arrDisplay.push(obj.display);
                    });
                    return arrDisplay;
                })()
            }
        ]
    });

    pickerHotelPriceRange = myApp.picker({
        input: '#sel_hotel_price_range_value',
        toolbarTemplate:
        '<div class="toolbar theme-red">' +
        '<div class="toolbar-inner">' +
        '<div class="left"></div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        formatValue: function (p, values, displayValues) {
            return displayValues;
        },
        cols: [
            {
                textAlign: 'center',
                values: (function () {
                    var arrValue = [];
                    $$.each(iss_dictionaryBaseData.hotelPriceRange(), function (i, obj) {
                        arrValue.push(obj.value);
                    });
                    return arrValue;
                })(),
                displayValues: (function () {
                    var arrDisplay = [];
                    $$.each(iss_dictionaryBaseData.hotelPriceRange(), function (i, obj) {
                        arrDisplay.push(obj.display);
                    });
                    return arrDisplay;
                })()
            }
        ]
    });

    calendarIn = myApp.calendar({
        input: '#calendar-in',
        dateFormat: 'yyyy.mm.dd',
        minDate: new Date(),
        maxDate: null,
        onClose: function (p) {
            if (calendarIn.length > 0)
                calendarOut.minDate = calendarIn.value[0];
        }
    });

    calendarOut = myApp.calendar({
        input: '#calendar-out',
        dateFormat: 'yyyy.mm.dd',
        minDate: new Date(),
        onClose: function (p) {
            if (calendarOut.length > 0)
                calendarIn.maxDate = calendarOut.value[0];
        }
    });

    //点击第一次页面执行
    var flag_tabs_tab1 = true;
    var flag_tabs_tab2 = true;
    //删除滚动后重新添加滚动
    var flag_InfiniteScroll = true;
    //是否需要滚动加载
    var flag_needScroll = true;
    //滚动事件只执行一次
    var flag_execute = false;

    var index_tab1 = 1;
    var index_tab2 = 1;
    var index_tab3 = 1;
    var index_tab4 = 1;
    var index_tab5 = 1;
    var current_tabindex = 0;
    var size = 10;
    // 加载flag
    var loading = false;

    current_tabindex = 1;
    $$("#sub_buttons_row a").eq(0).removeClass("active");
    $$("#sub_buttons_row a").eq(0).hide();
    $$("#sub_buttons_row a").eq(1).addClass("active");
    $$("#stay_tab2 #sub_tab1").removeClass("active");
    $$("#stay_tab2 #sub_tab2").addClass("active");
    // 默认加载全部
    // LoadStayAll(index_tab2, size);
    LoadStay();


    $$("#buttons-tabs a").click(function () {
        $$('.infinite-scroll').scrollTop(0);
        if ($$(this).index() == 0) {
            $$(".navbar-inner .right a img").hide();
            $$(".searchbar").hide();
            $$(".sub_buttons_row").hide();
            $$(".page-content").css("padding-top", "44px");
        }
        else {
            $$(".navbar-inner .right a img").show();
            $$(".searchbar").css("display", "");
            $$(".sub_buttons_row").css("display", "");
            $$(".page-content").css("padding-top", "");
        }

        if ($$(this).index() == 1 && flag_tabs_tab2) {
            LoadStayAll(index_tab1, size);
            flag_tabs_tab2 = false;
        }
        // if ($$(this).index() == 0 && flag_tabs_tab1) {
        //     LoadStay();
        //     flag_tabs_tab1 = false;
        // }
    });

    // 加载非住不可
    function LoadStay() {
        // 过滤
        // $$(".navbar-inner .right img").hide();
        // JSON
        var conditionParams = JSON.stringify({
            type: 7,
            Identifier: ISS_Constants.Identifier.zhu
        });
        //非住不可
        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.CMS,
            crossDomain: true,
            data: { "content": conditionParams },
            dataType: "jsonp",
            method: "POST",
            success: function (data, status) {
                data = JSON.parse(data);
                if (data && data.status && data.status == "0" && data.results && data.results.length > 0) {
                    for (var i = 0; i < data.results.length; i++) {
                        // 格式化数据
                        for (var j = 0; j < data.results[i].value.length; j++) {
                            if (data.results[i].value[j].F_SmallImage == undefined || data.results[i].value[j].F_SmallImage == null || data.results[i].value[j].F_SmallImage == "" || data.results[i].value[j].F_SmallImage.endWith('noPicture.jpg')) {
                                data.results[i].value[j].F_SmallImage = data.results[i].value[j].WEB_BASE_HOTEL_F_SmallImage;
                            };
                            if (data.results[i].value[j].Describes == undefined || data.results[i].value[j].Describes == null || data.results[i].value[j].Describes == "") {
                                data.results[i].value[j].Describes = data.results[i].value[j].WEB_BASE_HOTEL_Summary;
                            };
                            if (data.results[i].value[j].mobileOutUrl && data.results[i].value[j].mobileOutUrl != null &&
                                data.results[i].value[j].mobileOutUrl != "") {
                                data.results[i].value[j].mobileOutUrl = encodeURIComponent(data.results[i].value[j].mobileOutUrl);
                            };
                        }
                        if (data.results[i].name == "tuijianjiudian") {
                            var searchTemplate = $$('#template-stay-tab1').html();
                            if (searchTemplate) {
                                var compiledTemplate = Template7.compile(searchTemplate);
                                var html = compiledTemplate(data.results[i]);
                                $$("#stay_tab1 .content-block").html(html);
                                flag_InfiniteScroll = flag_needScroll = true;
                            }
                        }
                    }
                } else {
                    $$("#stay_tab1 .content-block").html("");
                }
            },
            error: function (xhr, status) { }
        });
    }; // end

    //加载全部
    function LoadStayAll(pageindex, pagesize) {
        // 检索条件
        var v_search = [];
        var v_order = [];

        var v_longitude = "";
        var v_latitude = "";

        //查询条件
        // 站点
        if (_cityCode != "") {
            var opt = {
                SearchField: "CityCode",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: _cityCode
                    }
                ]
            };
            v_search.push(opt);
        }

        // 区域
        if (pickerRegion && pickerRegion.value && pickerRegion.value.length > 0) {
            var opt = {
                SearchField: "District",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: pickerRegion.value[0]
                    }
                ]
            };
            v_search.push(opt);
        }

        //价格
        if (pickerHotelPriceRange && pickerHotelPriceRange.value && pickerHotelPriceRange.value.length > 0) {
            var opt = {
                SearchField: "Price",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: pickerHotelPriceRange.value[0]
                    }
                ]
            };
            v_search.push(opt);
        }

        //星级
        if (pickerHotelStar && pickerHotelStar.value && pickerHotelStar.value.length > 0) {
            var opt = {
                SearchField: "Star",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: pickerHotelStar.value[0]
                    }
                ]
            };
            v_search.push(opt);
        }

        //酒店类型
        if (pickerHotelType && pickerHotelType.value && pickerHotelType.value.length > 0) {
            var opt = {
                SearchField: "HotelType",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: pickerHotelType.value[0]
                    }
                ]
            };
            v_search.push(opt);
        }

        //住店时间
        if (calendarIn && calendarIn.value && calendarIn.value.length > 0) {
            var opt = {
                SearchField: "StartDate",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: calendarIn.input.val()
                    }
                ]
            };
            v_search.push(opt);
        }

        //离店时间
        if (calendarOut && calendarOut.value && calendarOut.value.length > 0) {
            var opt = {
                SearchField: "EndDate",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: calendarOut.input.val()
                    }
                ]
            };
            v_search.push(opt);
        }

        // 搜索条件
        if (mySearchbar && mySearchbar.query) {
            var opt = {
                SearchName: "名称",
                SearchField: "HotelKey",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: mySearchbar.query
                    }
                ]
            };
            v_search.push(opt);
        }

        // 排序
        if (current_tabindex == 0) {
            var opt = {
                OrderName: "最新",
                OrderField: "ModifyTime",
                OrderType: "desc"
            };
            v_order.push(opt);
        }
        else if (current_tabindex == 1) {
            var opt = {
                OrderField: "Sort",
                OrderType: "desc"
            };
            v_order.push(opt);
        }
        else if (current_tabindex == 2) {
            var opt = {
                OrderField: "ScoreOrder",
                OrderType: "desc"
            };
            v_order.push(opt);
        }
        else if (current_tabindex == 3) {
            var opt = {

                OrderField: "PriceOrder",
                OrderType: "asc"
            };
            v_order.push(opt);
        } else if (current_tabindex == 4) {
            var opt = {

                OrderField: "DistanceOrder",
                OrderType: "asc"
            };
            v_order.push(opt);
        }

        if (_isOpenPosition) {
            v_longitude = iss_localStorage.get("yuqing_longitude");
            v_latitude = iss_localStorage.get("yuqing_latitude");
        }
        else {
            v_longitude = iss_dictionaryBaseData.longitude;
            v_latitude = iss_dictionaryBaseData.latitude;
        }

        var jd_conditionParams = JSON.stringify({
            type: 0,
            conditionParams: {
                Page: {
                    PageSize: pagesize,
                    PageIndex: pageindex
                },
                Search: v_search,
                Order: v_order
            },
            lng: v_longitude,
            lat: v_latitude,
        });

        // var conditionParams = JSON.stringify({
        //     Page: {
        //         PageSize: pagesize,
        //         PageIndex: pageindex
        //     },
        //     Search: v_search,
        //     Order: v_order
        // });
        myApp.showPreloader();
        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.HOTEL,
            data: { content: jd_conditionParams },
            dataType: "jsonp",
            method: "GET",
            success: function (data, status) {
                myApp.hidePreloader();
                data = JSON.parse(data);
                loading = false;
                if (current_tabindex == 0 && index_tab1 == 1) {
                    $$("#stay_tab2 #sub_tab1 .content-block ul").children("li").remove();
                }
                if (current_tabindex == 1 && index_tab2 == 1) {
                    $$("#stay_tab2 #sub_tab2 .content-block ul").children("li").remove();
                }
                if (current_tabindex == 2 && index_tab3 == 1) {
                    $$("#stay_tab2 #sub_tab3 .content-block ul").children("li").remove();
                }
                if (current_tabindex == 3 && index_tab4 == 1) {
                    $$("#stay_tab2 #sub_tab4 .content-block ul").children("li").remove();
                }
                if (current_tabindex == 4 && index_tab5 == 1) {
                    $$("#stay_tab2 #sub_tab5 .content-block ul").children("li").remove();
                }

                if (data && data.status == "0" && data.results.length > 0) {

                    for (var i = 0; i < data.results.length; i++) {
                        data.results[i] = getDefaultImg(data.results[i]);
                        // 评分
                        data.results[i].colligationScore = formatScore(data.results[i].colligationScore);
                        // 距离
                        data.results[i].distance = ISS.utils.toFixed(data.results[i].distance, 2);
                        if (data.results[i].mobileOutUrl && data.results[i].mobileOutUrl != null &&
                            data.results[i].mobileOutUrl != "") {
                            data.results[i].mobileOutUrl = encodeURIComponent(data.results[i].mobileOutUrl);
                        };
                    };

                    var searchTemplate = $$('#template-stay-tab2').html();
                    if (searchTemplate) {
                        var compiledTemplate = Template7.compile(searchTemplate);
                        var html = compiledTemplate(data);
                        if (current_tabindex == 0) $$("#stay_tab2 #sub_tab1 .content-block ul").append(html);
                        else if (current_tabindex == 1) $$("#stay_tab2 #sub_tab2 .content-block ul").append(html);
                        else if (current_tabindex == 2) $$("#stay_tab2 #sub_tab3 .content-block ul").append(html);
                        else if (current_tabindex == 3) $$("#stay_tab2 #sub_tab4 .content-block ul").append(html);
                        else if (current_tabindex == 4) $$("#stay_tab2 #sub_tab5 .content-block ul").append(html);
                        flag_InfiniteScroll = flag_needScroll = true;
                    }

                    //tab1综合,无限滚动只加载一次
                    if (!flag_execute) {
                        //只执行一次
                        flag_execute = true;


                        $$('.infinite-scroll').on('infinite', function () {
                            //综合 价格 距离 切换
                            if (!flag_needScroll) {
                                flag_needScroll = true;
                                return;
                            }

                            //查询时,删除滚动后重新绑定pageindex
                            if (!flag_InfiniteScroll) {
                                flag_InfiniteScroll = true;
                                return;
                            }

                            if ($$("#a_food_tab2").hasClass("active")) {
                                // 如果正在加载，则退出
                                if (loading) return;
                                // 设置flag
                                loading = true;
                                // 模拟1s的加载过程
                                setTimeout(function () {
                                    if (current_tabindex == 0) {
                                        index_tab1++;
                                        LoadStayAll(index_tab1, pagesize);
                                    }
                                    else if (current_tabindex == 1) {
                                        index_tab2++;
                                        LoadStayAll(index_tab2, pagesize);
                                    }
                                    else if (current_tabindex == 2) {
                                        index_tab3++;
                                        LoadStayAll(index_tab3, pagesize);
                                    }
                                    else if (current_tabindex == 3) {
                                        index_tab4++;
                                        LoadStayAll(index_tab4, pagesize);
                                    }
                                    else if (current_tabindex == 4) {
                                        index_tab5++;
                                        LoadStayAll(index_tab5, pagesize);
                                    }
                                }, 100);
                            }
                        });
                    }
                    if (current_tabindex == 0 && $$("#stay_tab2 #sub_tab1 .content-block ul li").length >= data.total) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader1').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 1 && $$("#stay_tab2 #sub_tab2 .content-block ul li").length >= data.total) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader2').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 2 && $$("#stay_tab2 #sub_tab3 .content-block ul li").length >= data.total) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader3').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 3 && $$("#stay_tab2 #sub_tab4 .content-block ul li").length >= data.total) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader4').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 4 && $$("#stay_tab2 #sub_tab5 .content-block ul li").length >= data.total) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader5').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                }
                else {
                    // 删除加载提示符
                    myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    if (current_tabindex == 0) {
                        $$('.infinite-scroll-preloader1').remove();
                        // 删除多余的提示
                        $$("#stay_tab2 #sub_tab1 .content-block .noAnswer").remove();
                        if (pageindex == 1)
                            $$("#stay_tab2 #sub_tab1 .content-block").html(ISS_Element.DIV.noAnswer);
                        $$("#stay_tab2 #sub_tab1 .noAnswer").on("click", function () {
                            index_tab1 = 1;

                            LoadStayAll(index_tab1, current_tabindex);
                        });
                    }
                    else if (current_tabindex == 1) {
                        $$('.infinite-scroll-preloader2').remove();
                        // 删除多余的提示
                        $$("#stay_tab2 #sub_tab2 .content-block .noAnswer").remove();
                        if (pageindex == 1)
                            $$("#stay_tab2 #sub_tab2 .content-block").html(ISS_Element.DIV.noAnswer);
                        $$("#stay_tab2 #sub_tab2 .noAnswer").on("click", function () {
                            index_tab2 = 1;

                            LoadStayAll(index_tab2, current_tabindex);
                        });
                    }
                    else if (current_tabindex == 2) {
                        $$('.infinite-scroll-preloader3').remove();
                        // 删除多余的提示
                        $$("#stay_tab2 #sub_tab3 .content-block .noAnswer").remove();
                        if (pageindex == 1)
                            $$("#stay_tab2 #sub_tab3 .content-block").html(ISS_Element.DIV.noAnswer);
                        $$("#stay_tab2 #sub_tab3 .noAnswer").on("click", function () {
                            index_tab3 = 1;

                            LoadStayAll(index_tab3, current_tabindex);
                        });
                    }
                    else if (current_tabindex == 3) {
                        $$('.infinite-scroll-preloader4').remove();
                        // 删除多余的提示
                        $$("#stay_tab2 #sub_tab4 .content-block .noAnswer").remove();
                        if (pageindex == 1)
                            $$("#stay_tab2 #sub_tab4 .content-block").html(ISS_Element.DIV.noAnswer);
                        $$("#stay_tab2 #sub_tab4 .noAnswer").on("click", function () {
                            index_tab4 = 1;

                            LoadStayAll(index_tab4, current_tabindex);
                        });
                    }
                    else if (current_tabindex == 4) {
                        $$('.infinite-scroll-preloader5').remove();
                        // 删除多余的提示
                        $$("#stay_tab2 #sub_tab5 .content-block .noAnswer").remove();
                        if (pageindex == 1)
                            $$("#stay_tab2 #sub_tab5 .content-block").html(ISS_Element.DIV.noAnswer);
                        $$("#stay_tab2 #sub_tab5 .noAnswer").on("click", function () {
                            index_tab5 = 1;

                            LoadStayAll(index_tab5, current_tabindex);
                        });
                    }
                }
            },
            error: function (xhr, status) {
                myApp.hidePreloader();
                myApp.alert("服务器连接失败！");
                loading = false;
            }
        });
    }

    // 搜索
    var mySearchbar = myApp.searchbar('.searchbar', {
        customSearch: true,
        onClear: function (s) { // clear

        }
    });

    //搜索框 Enter
    $$(".searchbar-input input").keydown(function (key) {
        if (key.keyCode == 13) {
            myApp.attachInfiniteScroll($$('.infinite-scroll'));
            $$("#stay_tab2 #sub_tab1 .content-block ul").children("li").remove();
            $$("#stay_tab2 #sub_tab2 .content-block ul").children("li").remove();
            $$("#stay_tab2 #sub_tab3 .content-block ul").children("li").remove();
            $$("#stay_tab2 #sub_tab4 .content-block ul").children("li").remove();
            $$("#stay_tab2 #sub_tab5 .content-block ul").children("li").remove();
            $$(".noAnswer").remove();


            flag_InfiniteScroll = false;
            flag_needScroll = true;
            index_tab1 = index_tab2 = index_tab3 = index_tab4 = index_tab5 = 1;
            if (current_tabindex == 0) LoadStayAll(index_tab1, size);
            else if (current_tabindex == 1) LoadStayAll(index_tab2, size);
            else if (current_tabindex == 2) LoadStayAll(index_tab3, size);
            else if (current_tabindex == 3) LoadStayAll(index_tab4, size);
            else if (current_tabindex == 4) LoadStayAll(index_tab5, size);
        }
    });

    //查询条件
    $$(".view-right .right a.close-panel").on("click", function () {
        myApp.attachInfiniteScroll($$('.infinite-scroll'));
        $$("#stay_tab2 #sub_tab1 .content-block ul").children("li").remove();
        $$("#stay_tab2 #sub_tab2 .content-block ul").children("li").remove();
        $$("#stay_tab2 #sub_tab3 .content-block ul").children("li").remove();
        $$("#stay_tab2 #sub_tab4 .content-block ul").children("li").remove();
        $$("#stay_tab2 #sub_tab5 .content-block ul").children("li").remove();
        $$(".noAnswer").remove();


        flag_InfiniteScroll = false;
        flag_needScroll = true;
        index_tab1 = index_tab2 = index_tab3 = index_tab4 = index_tab5 = 1;
        if (current_tabindex == 0) LoadStayAll(index_tab1, size);
        else if (current_tabindex == 1) LoadStayAll(index_tab2, size);
        else if (current_tabindex == 2) LoadStayAll(index_tab3, size);
        else if (current_tabindex == 3) LoadStayAll(index_tab4, size);
        else if (current_tabindex == 4) LoadStayAll(index_tab5, size);
    });

    //综合 价格 距离切换
    $$("#sub_buttons_row a").on("click", function () {
        $$('.infinite-scroll').scrollTop(0);
        current_tabindex = $$(this).index();
        myApp.attachInfiniteScroll($$('.infinite-scroll'));

        flag_InfiniteScroll = true;
        flag_needScroll = false;
        if ($$(this).index() == 0 && $$("#stay_tab2 #sub_tab1 .content-block ul").children("li").length == 0) {
            LoadStayAll(index_tab1, size);
        }
        else if ($$(this).index() == 1 && $$("#stay_tab2 #sub_tab2 .content-block ul").children("li").length == 0) {
            LoadStayAll(index_tab2, size);
        }
        else if ($$(this).index() == 2 && $$("#stay_tab2 #sub_tab3 .content-block ul").children("li").length == 0) {
            LoadStayAll(index_tab3, size);
        }
        else if ($$(this).index() == 3 && $$("#stay_tab2 #sub_tab4 .content-block ul").children("li").length == 0) {
            LoadStayAll(index_tab4, size);
        }
        else if ($$(this).index() == 4 && $$("#stay_tab2 #sub_tab5 .content-block ul").children("li").length == 0) {
            LoadStayAll(index_tab5, size);
        }
    });
});

/* 酒店 */
var contactsCallback_hotel = myApp.onPageInit('hotel', function (page) {
    var type = ISS.utils.getParameter("type");
    if (type != null && type != undefined && type != "") {
        $$("#hotel_page .navbar .left a").attr("data-action", "history");
        $$("#hotel_page .navbar .left a i").removeClass("iconfont");
        $$("#hotel_page .navbar .left a i").removeClass("icon-shouye");
        $$("#hotel_page .navbar .left a i").addClass("icon");
        $$("#hotel_page .navbar .left a i").addClass("icon-back");
    }


    /* 筛选条件 */
    $$("#category_list ul li").hide();
    $$("#sel_hotel_price_range").show();
    $$("#sel_hotel_star").show();
    $$("#sel_hotel_type").show();


    var pickerRegion; //所在区域
    var pickerHotelStar; //酒店星级
    var pickerHotelType; //酒店类型
    var pickerHotelPriceRange; //价格范围
    var calendarIn; //入住时间
    var calendarOut; //离店时间

    pickerRegion = myApp.picker({
        input: '#sel_region_value',
        toolbarTemplate:
        '<div class="toolbar theme-red">' +
        '<div class="toolbar-inner">' +
        '<div class="left"></div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        formatValue: function (p, values, displayValues) {
            return displayValues;
        },
        cols: [
            {
                textAlign: 'center',
                values: (function () {
                    var arrValue = [];
                    $$.each(iss_dictionaryBaseData.district(), function (i, obj) {
                        arrValue.push(obj.value);
                    });
                    return arrValue;
                })(),
                displayValues: (function () {
                    var arrDisplay = [];
                    $$.each(iss_dictionaryBaseData.district(), function (i, obj) {
                        arrDisplay.push(obj.display);
                    });
                    return arrDisplay;
                })()
            }
        ]
    });

    pickerHotelStar = myApp.picker({
        input: '#sel_hotel_star_value',
        toolbarTemplate:
        '<div class="toolbar theme-red">' +
        '<div class="toolbar-inner">' +
        '<div class="left"></div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        formatValue: function (p, values, displayValues) {
            return displayValues;
        },
        cols: [
            {
                textAlign: 'center',
                values: (function () {
                    var arrValue = [];
                    $$.each(iss_dictionaryBaseData.hotelStar(), function (i, obj) {
                        arrValue.push(obj.value);
                    });
                    return arrValue;
                })(),
                displayValues: (function () {
                    var arrDisplay = [];
                    $$.each(iss_dictionaryBaseData.hotelStar(), function (i, obj) {
                        arrDisplay.push(obj.display);
                    });
                    return arrDisplay;
                })()
            }
        ]
    });

    pickerHotelType = myApp.picker({
        input: '#sel_hotel_type_value',
        toolbarTemplate:
        '<div class="toolbar theme-red">' +
        '<div class="toolbar-inner">' +
        '<div class="left"></div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        formatValue: function (p, values, displayValues) {
            return displayValues;
        },
        cols: [
            {
                textAlign: 'center',
                values: (function () {
                    var arrValue = [];
                    $$.each(iss_dictionaryBaseData.hotelType(), function (i, obj) {
                        arrValue.push(obj.value);
                    });
                    return arrValue;
                })(),
                displayValues: (function () {
                    var arrDisplay = [];
                    $$.each(iss_dictionaryBaseData.hotelType(), function (i, obj) {
                        arrDisplay.push(obj.display);
                    });
                    return arrDisplay;
                })()
            }
        ]
    });

    pickerHotelPriceRange = myApp.picker({
        input: '#sel_hotel_price_range_value',
        toolbarTemplate:
        '<div class="toolbar theme-red">' +
        '<div class="toolbar-inner">' +
        '<div class="left"></div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        formatValue: function (p, values, displayValues) {
            return displayValues;
        },
        cols: [
            {
                textAlign: 'center',
                values: (function () {
                    var arrValue = [];
                    $$.each(iss_dictionaryBaseData.hotelPriceRange(), function (i, obj) {
                        arrValue.push(obj.value);
                    });
                    return arrValue;
                })(),
                displayValues: (function () {
                    var arrDisplay = [];
                    $$.each(iss_dictionaryBaseData.hotelPriceRange(), function (i, obj) {
                        arrDisplay.push(obj.display);
                    });
                    return arrDisplay;
                })()
            }
        ]
    });

    function checkTime(k) {
        if (k < 10) {
            k = "0" + k;
        }
        return k;
    }

    calendarIn = myApp.calendar({
        input: '#calendar-in',
        dateFormat: 'yyyy.mm.dd',
        minDate: new Date(),
        maxDate: null,
        onClose: function (p) {
            if (calendarIn.length > 0)
                calendarOut.minDate = calendarIn.value[0];
        },
        onDayClick: function (p, dayContainer, year, month, day) {
            var fulldate = year + "-" + checkTime(parseInt(month) + 1) + "-" + checkTime(day);
            if (calendarOut != undefined) {
                //var minDate_str = GetDateStr(1, ISS.utils.strToDate(fulldate));
                calendarOut.params.minDate = fulldate;
            }
        }
    });

    calendarOut = myApp.calendar({
        input: '#calendar-out',
        dateFormat: 'yyyy.mm.dd',
        minDate: new Date(),
        onClose: function (p) {
            if (calendarOut.length > 0)
                calendarIn.maxDate = calendarOut.value[0];
        }
    });

    //删除滚动后重新添加滚动
    var flag_InfiniteScroll = true;
    //是否需要滚动加载
    var flag_needScroll = true;
    //滚动事件只执行一次
    var flag_execute = false;

    var index_tab1 = 1;
    var index_tab2 = 1;
    var index_tab3 = 1;
    var index_tab4 = 1;
    var index_tab5 = 1;
    var current_tabindex = 0;
    var size = 10;
    // 加载flag
    var loading = false;


    current_tabindex = 1;
    $$("#sub_buttons_row a").eq(0).removeClass("active");
    $$("#sub_buttons_row a").eq(0).hide();
    $$("#sub_buttons_row a").eq(1).addClass("active");
    $$("#stay_tab2 #sub_tab1").removeClass("active");
    $$("#stay_tab2 #sub_tab2").addClass("active");
    // 默认加载全部
    LoadStayAll(index_tab2, size);


    //加载数据
    function LoadStayAll(pageindex, pagesize) {

        // 检索条件
        var v_search = [];
        var v_order = [];

        var v_longitude = "";
        var v_latitude = "";

        //查询条件
        // 站点
        if (_cityCode != "") {
            var opt = {
                SearchField: "CityCode",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: _cityCode
                    }
                ]
            };
            v_search.push(opt);
        }

        // 区域
        if (pickerRegion && pickerRegion.value && pickerRegion.value.length > 0) {
            var opt = {
                SearchField: "District",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: pickerRegion.value[0]
                    }
                ]
            };
            v_search.push(opt);
        }

        //价格
        if (pickerHotelPriceRange && pickerHotelPriceRange.value && pickerHotelPriceRange.value.length > 0) {
            var opt = {
                SearchField: "Price",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: pickerHotelPriceRange.value[0]
                    }
                ]
            };
            v_search.push(opt);
        }

        //星级
        if (pickerHotelStar && pickerHotelStar.value && pickerHotelStar.value.length > 0) {
            var opt = {
                SearchField: "Star",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: pickerHotelStar.value[0]
                    }
                ]
            };
            v_search.push(opt);
        }

        //酒店类型
        if (pickerHotelType && pickerHotelType.value && pickerHotelType.value.length > 0) {
            var opt = {
                SearchField: "HotelType",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: pickerHotelType.value[0]
                    }
                ]
            };
            v_search.push(opt);
        }

        //住店时间
        if (calendarIn && calendarIn.value && calendarIn.value.length > 0) {
            var opt = {
                SearchField: "StartDate",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: calendarIn.input.val()
                    }
                ]
            };
            v_search.push(opt);
        }

        //离店时间
        if (calendarOut && calendarOut.value && calendarOut.value.length > 0) {
            var opt = {
                SearchField: "EndDate",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: calendarOut.input.val()
                    }
                ]
            };
            v_search.push(opt);
        }

        // 搜索条件
        if (mySearchbar && mySearchbar.query) {
            var opt = {
                SearchName: "名称",
                SearchField: "HotelKey",
                ConditionType: 1,
                AndOR: "and",
                ListSearchValue: [
                    {
                        ItemValue: mySearchbar.query
                    }
                ]
            };
            v_search.push(opt);
        }

        // 排序
        if (current_tabindex == 0) {
            var opt = {
                OrderName: "最新",
                OrderField: "ModifyTime", //排序字段
                OrderType: "desc"
            };
            v_order.push(opt);
        }
        else if (current_tabindex == 1) {
            var opt = {
                OrderField: "Sort",
                OrderType: "desc"
            };
            v_order.push(opt);
        }
        else if (current_tabindex == 2) {
            var opt = {
                OrderField: "ScoreOrder",
                OrderType: "desc"
            };
            v_order.push(opt);
        }
        else if (current_tabindex == 3) {
            var opt = {

                OrderField: "PriceOrder",
                OrderType: "asc"
            };
            v_order.push(opt);
        } else if (current_tabindex == 4) {
            var opt = {

                OrderField: "DistanceOrder",
                OrderType: "asc"
            };
            v_order.push(opt);
        }

        if (_isOpenPosition) {
            v_longitude = iss_localStorage.get("yuqing_longitude");
            v_latitude = iss_localStorage.get("yuqing_latitude");
        }
        else {
            v_longitude = iss_dictionaryBaseData.longitude;
            v_latitude = iss_dictionaryBaseData.latitude;
        }

        var jd_conditionParams = JSON.stringify({
            type: 0,
            conditionParams: {
                Page: {
                    PageSize: pagesize,
                    PageIndex: pageindex
                },
                Search: v_search,
                Order: v_order
            },
            lng: v_longitude,
            lat: v_latitude,
        });

        myApp.showPreloader();
        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.HOTEL,
            data: { content: jd_conditionParams },
            dataType: "jsonp",

            method: "GET",
            success: function (data, status) {
                myApp.hidePreloader();
                data = JSON.parse(data);
                loading=false;
                if (current_tabindex == 0 && index_tab1 == 1) {
                    $$("#stay_tab2 #sub_tab1 .content-block ul").children("li").remove();
                }
                if (current_tabindex == 1 && index_tab2 == 1) {
                    $$("#stay_tab2 #sub_tab2 .content-block ul").children("li").remove();
                }
                if (current_tabindex == 2 && index_tab3 == 1) {
                    $$("#stay_tab2 #sub_tab3 .content-block ul").children("li").remove();
                }
                if (current_tabindex == 3 && index_tab4 == 1) {
                    $$("#stay_tab2 #sub_tab4 .content-block ul").children("li").remove();
                }
                if (current_tabindex == 4 && index_tab5 == 1) {
                    $$("#stay_tab2 #sub_tab5 .content-block ul").children("li").remove();
                }
                if (data && data.status == "0" && data.results.length > 0) {
                    // 数据格式化
                    for (var i = 0; i < data.results.length; i++) {
                        data.results[i] = getDefaultImg(data.results[i]);
                        // 评分
                        data.results[i].colligationScore = formatScore(data.results[i].colligationScore);
                        // 距离
                        data.results[i].distance = ISS.utils.toFixed(data.results[i].distance, 2);
                        if (data.results[i].mobileOutUrl && data.results[i].mobileOutUrl != null &&
                            data.results[i].mobileOutUrl != "") {
                            data.results[i].mobileOutUrl = encodeURIComponent(data.results[i].mobileOutUrl);
                        };
                    };
                    // 模板
                    var searchTemplate = $$('#template-stay-tab2').html();
                    if (searchTemplate) {
                        var compiledTemplate = Template7.compile(searchTemplate);
                        var html = compiledTemplate(data);
                        if (current_tabindex == 0) $$("#stay_tab2 #sub_tab1 .content-block ul").append(html);
                        if (current_tabindex == 1) $$("#stay_tab2 #sub_tab2 .content-block ul").append(html);
                        if (current_tabindex == 2) $$("#stay_tab2 #sub_tab3 .content-block ul").append(html);
                        if (current_tabindex == 3) $$("#stay_tab2 #sub_tab4 .content-block ul").append(html);
                        if (current_tabindex == 4) $$("#stay_tab2 #sub_tab5 .content-block ul").append(html);
                        flag_InfiniteScroll = flag_needScroll = true;
                    }

                    //tab1综合,无限滚动只加载一次
                    if (!flag_execute) {
                        //只执行一次
                        flag_execute = true;

                        

                        $$('.infinite-scroll').on('infinite', function () {
                            //综合 价格 距离 切换
                            if (!flag_needScroll) {
                                flag_needScroll = true;
                                return;
                            }

                            //查询时,删除滚动后重新绑定pageindex
                            if (!flag_InfiniteScroll) {
                                flag_InfiniteScroll = true;
                                return;
                            }

                            if (true) {
                                // 如果正在加载，则退出
                                if (loading) return;
                                // 设置flag
                                loading = true;
                                // 模拟1s的加载过程
                                setTimeout(function () {
                               
                                    if (current_tabindex == 0) {
                                        index_tab1++;
                                        LoadStayAll(index_tab1, pagesize);
                                    }
                                    else if (current_tabindex == 1) {
                                        index_tab2++;
                                        LoadStayAll(index_tab2, pagesize);
                                    }
                                    else if (current_tabindex == 2) {
                                        index_tab3++;
                                        LoadStayAll(index_tab3, pagesize);
                                    }
                                    else if (current_tabindex == 3) {
                                        index_tab4++;
                                        LoadStayAll(index_tab4, pagesize);
                                    }
                                    else if (current_tabindex == 4) {
                                        index_tab5++;
                                        LoadStayAll(index_tab5, pagesize);
                                    }

                                }, 100);
                            }
                        });

                    }
                    if (current_tabindex == 0 && $$("#stay_tab2 #sub_tab1 .content-block ul li").length >= data.total) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader1').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 1 && $$("#stay_tab2 #sub_tab2 .content-block ul li").length >= data.total) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader2').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 2 && $$("#stay_tab2 #sub_tab3 .content-block ul li").length >= data.total) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader3').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 3 && $$("#stay_tab2 #sub_tab4 .content-block ul li").length >= data.total) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader4').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                    else if (current_tabindex == 4 && $$("#stay_tab2 #sub_tab5 .content-block ul li").length >= data.total) {
                        // 删除加载提示符
                        $$('.infinite-scroll-preloader5').remove();
                        // 加载完毕，则注销无限加载事件，以防不必要的加载
                        myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    }
                }
                else {
                    // 删除加载提示符
                    myApp.detachInfiniteScroll($$('.infinite-scroll'));
                    if (current_tabindex == 0) {
                        $$('.infinite-scroll-preloader1').remove();
                        // 删除多余的提示
                        $$("#stay_tab2 #sub_tab1 .content-block .noAnswer").remove();
                        if (pageindex == 1)
                            $$("#stay_tab2 #sub_tab1 .content-block").html(ISS_Element.DIV.noAnswer);
                        $$("#stay_tab2 #sub_tab1 .noAnswer").on("click", function () {
                            index_tab1 = 1;

                            LoadStayAll(index_tab1, current_tabindex);
                        });
                    }
                    else if (current_tabindex == 1) {
                        $$('.infinite-scroll-preloader2').remove();
                        // 删除多余的提示
                        $$("#stay_tab2 #sub_tab2 .content-block .noAnswer").remove();
                        if (pageindex == 1)
                            $$("#stay_tab2 #sub_tab2 .content-block").html(ISS_Element.DIV.noAnswer);
                        $$("#stay_tab2 #sub_tab2 .noAnswer").on("click", function () {
                            index_tab2 = 1;

                            LoadStayAll(index_tab2, current_tabindex);
                        });
                    }
                    else if (current_tabindex == 2) {
                        $$('.infinite-scroll-preloader3').remove();
                        // 删除多余的提示
                        $$("#stay_tab2 #sub_tab3 .content-block .noAnswer").remove();
                        if (pageindex == 1)
                            $$("#stay_tab2 #sub_tab3 .content-block").html(ISS_Element.DIV.noAnswer);
                        $$("#stay_tab2 #sub_tab3 .noAnswer").on("click", function () {
                            index_tab3 = 1;

                            LoadStayAll(index_tab3, current_tabindex);
                        });
                    }
                    else if (current_tabindex == 3) {
                        $$('.infinite-scroll-preloader4').remove();
                        // 删除多余的提示
                        $$("#stay_tab2 #sub_tab4 .content-block .noAnswer").remove();
                        if (pageindex == 1)
                            $$("#stay_tab2 #sub_tab4 .content-block").html(ISS_Element.DIV.noAnswer);
                        $$("#stay_tab2 #sub_tab4 .noAnswer").on("click", function () {
                            index_tab4 = 1;

                            LoadStayAll(index_tab4, current_tabindex);
                        });
                    }
                    else if (current_tabindex == 4) {
                        $$('.infinite-scroll-preloader5').remove();
                        // 删除多余的提示
                        $$("#stay_tab2 #sub_tab5 .content-block .noAnswer").remove();
                        if (pageindex == 1)
                            $$("#stay_tab2 #sub_tab5 .content-block").html(ISS_Element.DIV.noAnswer);
                        $$("#stay_tab2 #sub_tab5 .noAnswer").on("click", function () {
                            index_tab5 = 1;

                            LoadStayAll(index_tab5, current_tabindex);
                        });
                    }
                }
            },
            error: function (xhr, status) {
                myApp.hidePreloader();
                myApp.alert("服务器连接失败！");
                loading=false;
            }
        });
    };

    // 搜索
    var mySearchbar = myApp.searchbar('.searchbar', {
        customSearch: true,
        onClear: function (s) { // clear

        }
    });

    //搜索框 Enter
    $$(".searchbar-input input").keydown(function (key) {
        if (key.keyCode == 13) {
            myApp.attachInfiniteScroll($$('.infinite-scroll'));
            $$("#stay_tab2 #sub_tab1 .content-block ul").children("li").remove();
            $$("#stay_tab2 #sub_tab2 .content-block ul").children("li").remove();
            $$("#stay_tab2 #sub_tab3 .content-block ul").children("li").remove();
            $$("#stay_tab2 #sub_tab4 .content-block ul").children("li").remove();
            $$("#stay_tab2 #sub_tab5 .content-block ul").children("li").remove();
            $$(".noAnswer").remove();


            flag_InfiniteScroll = false;
            flag_needScroll = true;
            index_tab1 = index_tab2 = index_tab3 = index_tab4 = index_tab5 = 1;
            if (current_tabindex == 0) LoadStayAll(index_tab1, size);
            else if (current_tabindex == 1) LoadStayAll(index_tab2, size);
            else if (current_tabindex == 2) LoadStayAll(index_tab3, size);
            else if (current_tabindex == 3) LoadStayAll(index_tab4, size);
            else if (current_tabindex == 4) LoadStayAll(index_tab5, size);
        }
    });

    //查询条件
    $$(".view-right .right a.close-panel").on("click", function () {
        myApp.attachInfiniteScroll($$('.infinite-scroll'));
        $$("#stay_tab2 #sub_tab1 .content-block ul").children("li").remove();
        $$("#stay_tab2 #sub_tab2 .content-block ul").children("li").remove();
        $$("#stay_tab2 #sub_tab3 .content-block ul").children("li").remove();
        $$("#stay_tab2 #sub_tab4 .content-block ul").children("li").remove();
        $$("#stay_tab2 #sub_tab5 .content-block ul").children("li").remove();
        $$(".noAnswer").remove();


        flag_InfiniteScroll = false;
        flag_needScroll = true;
        index_tab1 = index_tab2 = index_tab3 = index_tab4 = index_tab5 = 1;
        if (current_tabindex == 0) LoadStayAll(index_tab1, size);
        else if (current_tabindex == 1) LoadStayAll(index_tab2, size);
        else if (current_tabindex == 2) LoadStayAll(index_tab3, size);
        else if (current_tabindex == 3) LoadStayAll(index_tab4, size);
        else if (current_tabindex == 4) LoadStayAll(index_tab5, size);
    });

    //综合 价格 距离切换
    $$("#sub_buttons_row").on("click", "a", function () {
        $$('.infinite-scroll').scrollTop(0);
        current_tabindex = $$(this).index();
        myApp.attachInfiniteScroll($$('.infinite-scroll'));

        flag_InfiniteScroll = true;
        flag_needScroll = false;
        if ($$(this).index() == 0 && $$("#stay_tab2 #sub_tab1 .content-block ul").children("li").length == 0) {
            LoadStayAll(index_tab1, size);
        }
        else if ($$(this).index() == 1 && $$("#stay_tab2 #sub_tab2 .content-block ul").children("li").length == 0) {
            LoadStayAll(index_tab2, size);
        }
        else if ($$(this).index() == 2 && $$("#stay_tab2 #sub_tab3 .content-block ul").children("li").length == 0) {
            LoadStayAll(index_tab3, size);
        }
        else if ($$(this).index() == 3 && $$("#stay_tab2 #sub_tab4 .content-block ul").children("li").length == 0) {
            LoadStayAll(index_tab4, size);
        }
        else if ($$(this).index() == 4 && $$("#stay_tab2 #sub_tab5 .content-block ul").children("li").length == 0) {
            LoadStayAll(index_tab5, size);
        }
    });
});

/* 酒店详情  */
var contactsCallback_hotelDetail = myApp.onPageInit('hotelDetail', function (page) {
    //获取页面参数
    var code = ISS.utils.getParameter("code");
    if (page != undefined) {
        code = page.query.code;
    }
    //加载酒店
    load_hotel();
    function load_hotel() {
        var _content = JSON.stringify({
            type: 1,
            Code: code
        });

        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.HOTEL,
            data: { "content": _content },

            crossDomain: true,
            method: "GET",
            success: function (data, status) {
                data = JSON.parse(data);

                if (data && data.status == "0" && data.results) {
                    data.results = getDefaultImg(data.results);
                    //简介
                    data.results.shortsummary = "";
                    if (data.results.summary.length > 130) {
                        data.results.shortsummary = data.results.summary.substring(0, 130) + "...";
                    }
                    //房型图片
                    if (data.results.roomList.length > 0) {
                        for (var i = 0; i < data.results.roomList.length; i++) {
                            var ListPic = data.results.roomList[i].getImage;
                            if (ListPic == undefined || ListPic == null) {
                                data.results.roomList[i].getImage = {
                                    imageFrontUrl: NoPicture(),
                                    imageList: [],
                                    largeImageFrontUrl: NoPicture(),
                                    middleImageFrontUrl: NoPicture(),
                                    smallImageFrontUrl: NoPicture()
                                }
                            }
                            else {
                                var imageList1 = [];
                                for (var j = 0; j < data.results.roomList[i].getImage.imageList.length; j++) {
                                    imageList1.push(data.results.roomList[i].getImage.imageList[j].middleImgSrc);
                                }
                                data.results.roomList[i].getImage.imageList1 = imageList1;
                            }
                        }
                    }
 
                    //加载数据模板
                    var searchTemplate = $$('#template-hotel-detail').html();
                    var compiledSearchTemplate = Template7.compile(searchTemplate);
                    var html = compiledSearchTemplate(data.results);
                    $$("#hotel_detail_page .page-content span.hotel_info").html(html);
                    //头部图片滑动
                    if (data.results.getImage.imageList.length > 0) {
                        var slidesperview = 3;
                        if (data.results.getImage.imageList.length == 1) {
                            slidesperview = 1;
                        } else if (data.results.getImage.imageList.length == 2) {
                            slidesperview = 2;
                        }

                        var mySwiper = new Swiper('.swiper-hotelDetail', {
                            pagination: '.swiper-hotelDetail .swiper-pagination',
                            autoplay: 5000,
                            speed: 300,
                            spaceBetween: 5,
                            slidesPerView: slidesperview
                        });

                        var ImageList = [];
                        var middleImageList = [];
                        for (var i = 0; i < data.results.getImage.imageList.length; i++) {
                            ImageList[i] = data.results.getImage.imageList[i].smallImgSrc;
                            middleImageList[i] = data.results.getImage.imageList[i].middleImgSrc;
                        }
                        $$("#hotel_detail_page #swiper").attr("yuqing_ImgList", JSON.stringify(ImageList));
                        $$("#hotel_detail_page #swiper").attr("yuqing_middleImageList", JSON.stringify(middleImageList));

                        $$("#hotel_detail_page #swiper").on("click", function () {
                            event.stopPropagation();
                            iss_localStorage.set("yuqing_ImgList", JSON.parse($$(this).attr("yuqing_ImgList")));
                            iss_localStorage.set("yuqing_middleImageList", JSON.parse($$(this).attr("yuqing_middleImageList")));
                            mainView.router.load({ url: "../../view/common/showImageList.html" });
                        })
                    }
                }
            },
            error: function (xhr, status) {
                console.log("ajax error!");

            }
        });

        $$("#hotel_detail_page .page-content").on("click", "div.swiper-container", function () {
            mainView.router.loadPage({ url: $$(this).attr("data-href"), reload: false });
            // window.location.href=$$(this).attr("data-href");
        })
    }

    //图片编辑
    $$('#hotel_detail_page .page-content').on('click', ".room-img img", function (e) {
        var photos = [];
        var imageList = $$(this).attr("imageList").split(",");
        if (imageList == undefined || imageList == "" || imageList.length == undefined || imageList.length == 0) return;
        var img = $$(this);
        $$.each(imageList, function (i, obj) {
            photos.push({ url: obj, caption: $$(img).attr("cnName") });
        });

        var myPhotoBrowser = myApp.photoBrowser({
            zoom: true,
            exposition: true,
            navbar: true,
            backLinkText: "返回",
            ofText: " / ",
            theme: 'dark',
            photos: photos
        });
        myPhotoBrowser.open(); // 打开图片浏览器

    });
    //加载景区
    load_senic();
    function load_senic() {
        var v_order = [];
        var opt = {
            OrderField: "Distance",
            OrderType: "asc"
        };
        v_order.push(opt);

        var v_longitude = "";
        var v_latitude = "";
        if (_isOpenPosition) {
            v_longitude = iss_localStorage.get("yuqing_longitude");
            v_latitude = iss_localStorage.get("yuqing_latitude");
        }
        else {
            v_longitude = iss_dictionaryBaseData.longitude;
            v_latitude = iss_dictionaryBaseData.latitude;
        }
        // 参数
        var _content = JSON.stringify({
            type: 0,
            conditionParams: {
                Page: {
                    PageSize: 3,
                    PageIndex: 1
                },
                Search: [],
                Order: v_order
            },
            lng: v_longitude,
            lat: v_latitude,
        });



        $$.ajax({
            url: ISS_Constants.Url.defaulturl + ISS_Constants.serviceName.ATTAR,
            data: { content: _content },

            // dataType: "json",
            method: "GET",
            success: function (data, status) {
                data = JSON.parse(data);
                $$("#hotel_detail_page .loader").hide();
                if (data && data.status == "0" && data.results.length > 0) {
                    // 格式化数据
                    var html = "";
                    for (var i = 0; i < data.results.length; i++) {
                        if (data.results[i].getImage == null || data.results[i].getImage == undefined) {
                            data.results[i].getImage = { smallImageFrontUrl: NoPicture() };
                        };
                        data.results[i].distance = ISS.utils.toFixed(data.results[i].distance, 2);
                        html += '<a href="#" class="col-33" data-action="fw7"  data-href="../../view/booking/ticketDetail.html?ticketdetail_guid=' + data.results[i].code + '">';
                        html += '<div class="surround-img" style="background-image:url(' + data.results[i].getImage.smallImageFrontUrl + ')"></div>';
                        html += '<p>' + data.results[i].cnName + '</p>';
                        html += '<span>距离' + data.results[i].distance + 'km</span>';
                        html += '</a>';
                    }
                    if (html != "") {
                        $$("#hotel_detail_page .page-content span.scenic_list div.row").html(html);
                        $$("#hotel_detail_page .page-content span.scenic_list").show();
                    }
                }
                else {
                }
            },
            error: function (xhr, status) {
                console.log("ajax error!");
            }
        });
    }

    //预订按钮
    $$("#hotel_detail_page .page-content").on("click", "a.btn-booking[href='#']", function (e) {
        //取消原有跳转事件
        e.stopPropagation();
        //保存当前控件
        var mythis = $$(this);
        //跳转判断
        CheckPopLogin(function () {
            //window.location.href = mythis.attr("data-href");
            mainView.router.loadPage({ url: mythis.attr("data-href"), reload: false });
        });
    })

    $$("#hotel_detail_page .page-content").on("click", "a.more", function () {
        var action = $$(this).find("i")[0];
        if ($$(action).hasClass("icon-gengduo")) {
            //显示更多
            $$(this).prev("p.all").show().prev("p.short").hide();
            $$(action).removeClass("icon-gengduo").addClass("icon-shouqi");
            var html = $$(action).parent().html();
            html = html.replace("查看", "收起");
            $$(action).parent().html(html);
        }
        else {
            $$(this).prev("p.all").hide().prev("p.short").show();
            $$(action).removeClass("icon-shouqi").addClass("icon-gengduo");
            var html = $$(action).parent().html();
            html = html.replace("收起", "查看");
            $$(action).parent().html(html);
        }
    })
});

/* 初始化  */
function initData() {
    var href = window.location.href;
    if (href.indexOf(stay) > -1) {
        contactsCallback_stay.trigger();
    }
    else if (href.indexOf(hotel) > -1) {
        contactsCallback_hotel.trigger();
    }
    else if (href.indexOf(hotelDetail) > -1) {
        contactsCallback_hotelDetail.trigger();
    }
    else if (href.indexOf(hotelBooking) > -1) {
        contactsCallback_hotelBooking.trigger();
    }
    else if (href.indexOf(hotelPay) > -1) {
        contactsCallback_hotelPay.trigger();
    }
}

initData();

